package com.atguigu.gulimall.product.api;

import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.wxutil.ApiBaseAction;
import com.atguigu.gulimall.product.wxvo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 商品三级分类
 *
 * @author leifengyang
 * @email leifengyang@gmail.com
 * @date 2019-10-01 22:50:32
 */
@RestController
@RequestMapping("/api/catalog")
public class CategorysController extends ApiBaseAction {
    @Autowired
    private CategoryService categoryService;

    @PostMapping("/index")
    public Object index(Integer id,
                        @RequestParam(value = "page", defaultValue = "1") Integer page,
                        @RequestParam(value = "size", defaultValue = "10") Integer size){
        Map<String, Object> resultObj = new HashMap();
        Map params = new HashMap();
        params.put("page", page);
        params.put("limit", size);
        params.put("sidx", "sort_order");
        params.put("order", "asc");
        params.put("parent_id", 0);
        //查询列表分类
        List<CategoryEntity> level1Categorys = categoryService.getLevel1Categorys();

        List<CategoryVo> data = level1Categorys.stream().map(categoryVo -> {
            CategoryVo categoryVos = new CategoryVo();
            categoryVos.setName(categoryVo.getName());
            categoryVos.setIs_show(1);
            categoryVos.setShow_index(2);
            categoryVos.setType(0);
            categoryVos.setChecked(false);

            return categoryVos;
        }).collect(Collectors.toList());

        resultObj.put("categoryList", data);

        CategoryVo catelog = new CategoryVo();
        catelog.setId(1036000);
        catelog.setName("夏凉");
        catelog.setShow_index(1);
        catelog.setIs_show(1);
        List<CategoryVo> data2=new ArrayList<>();
        data2.add(catelog);
        for(int i=0;i<data2.size();i++){
            data.get(0).setSubCategoryList(data2);
        }

        return toResponsSuccess(resultObj);
    }


}
